#include "settingspage.h"
#include <QMessageBox>
#include <QVBoxLayout>
#include <QHBoxLayout>

SettingsPage::SettingsPage(QWidget *parent) : QWidget(parent)
{
    initUI();
}

SettingsPage::~SettingsPage()
{
}

void SettingsPage::initUI()
{
    // 创建主布局
    QVBoxLayout *mainLayout = new QVBoxLayout(this);

    // 创建表单布局用于设置项
    QFormLayout *formLayout = new QFormLayout();

    // 添加设置项
    QLineEdit *userNameEdit = new QLineEdit(this);
    QLineEdit *languageEdit = new QLineEdit(this);

    formLayout->addRow("用户名:", userNameEdit);
    formLayout->addRow("语言:", languageEdit);

    // 创建按钮布局
    QHBoxLayout *buttonLayout = new QHBoxLayout();
    QPushButton *saveButton = new QPushButton("保存设置", this);
    QPushButton *cancelButton = new QPushButton("取消", this);

    buttonLayout->addStretch();
    buttonLayout->addWidget(saveButton);
    buttonLayout->addWidget(cancelButton);
    buttonLayout->addStretch();

    // 连接保存按钮的信号和槽
    connect(saveButton, &QPushButton::clicked, this, &SettingsPage::saveSettings);

    // 添加到主布局
    mainLayout->addLayout(formLayout);
    mainLayout->addSpacing(20);
    mainLayout->addLayout(buttonLayout);
    mainLayout->addStretch();

    // 设置主布局
    setLayout(mainLayout);
}

void SettingsPage::saveSettings()
{
    QMessageBox::information(this, "提示", "设置已保存!");
}
